// WinMacroLib.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"
#include "WinMacroLib.h"
#include "RecordingSession.h"
#include "PlaybackSession.h"
#include "MacroFileReader.h"

#include <fstream>
#include <vector>

std::vector<EVENTMSG> message_list;

BOOL add_to_recorded_time=TRUE;
BOOL normal_speed=TRUE;
int time_interval=0;
int repeat_count=0;
BOOL g_record_mouse_actions = TRUE;

HHOOK g_getmsg_hook_handle;
HHOOK g_callwndretproc_hook_handle;
BOOL playing_back = FALSE;

HINSTANCE g_hinstance;

CRecordingSession * g_pRecordingSession = NULL;
CPlaybackSession * g_pPlaybackSession = NULL;

extern "C" WINMACROLIB_API DWORD PlaybackFrom(LPCTSTR fileName, PLAYBACKOPTIONS options, PLAYBACKSTOPPEDPROC proc,
											  PLAYBACKPROGRESSPROC playback_progress_proc)
{
	g_pPlaybackSession = new CPlaybackSession(fileName, g_hinstance, options, proc, playback_progress_proc);
	return g_pPlaybackSession->Start();
}

extern "C" WINMACROLIB_API DWORD RecordTo(LPCTSTR fileName, RECORDINGOPTIONS options, RECORDINGSTOPPEDPROC proc)
{
	if (playing_back) return 0;

	g_pRecordingSession = new CRecordingSession(fileName, g_hinstance, options, proc);
	return g_pRecordingSession->Start();
}

extern "C" WINMACROLIB_API DWORD ReadMacroFile(LPCTSTR fileName, EVENTMSG **messages, DWORD *message_count)
{
	CMacroFileReader reader;
	return reader.ReadMacroFile(fileName, messages, message_count);
}

extern "C" WINMACROLIB_API DWORD WriteMacroFile(LPCTSTR fileName, EVENTMSG* messages, DWORD message_count)
{
	CMacroFileWriter writer;
	return writer.WriteMacroFile(fileName, messages, message_count);
}
